import json
import os

input_file = "advbench.jsonl"
file_key = os.path.splitext(os.path.basename(input_file))[0]
output_file = f"./transfer/{file_key}.jsonl"
os.makedirs(os.path.dirname(output_file), exist_ok=True)

with open(input_file, "r", encoding="utf-8") as fin, open(output_file, "w", encoding="utf-8") as fout:
    for idx, line in enumerate(fin):
        data = json.loads(line)
        new_data = {
            "task": "<S2TCHAT>",
            "key": f"{file_key}_{idx}",
            "wav": data["audio_path"],
            "txt": data["prompt"],
            "lang": "<CN>",
            "speaker": "<NONE>",
            "emotion": "<NONE>",
            "gender": "<NONE>",
            "extra": {
                "duration": "<NONE>",
                "dataset": f"{file_key}"
            }
        }
        fout.write(json.dumps(new_data, ensure_ascii=False) + "\n")